/*
 * @Date: 2021-09-07 20:29:47
 * @Author: Acckno1
 * @LastEditTime: 2021-09-07 20:49:44
 * @Description: 
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 30;

int l[N], r[N], v[N], h[N], idx;

void update(int u) {
    h[u] = max(h[l[u]], h[r[u]]) + 1;
}

void R(int& u) {
    int p = l[u];
    l[u] = r[p];
    r[p] = u;
    update(u), update(p);
    u = p;
}

void L(int& u) {
    int p = r[u];
    r[u] = l[p];
    l[p] = u;
    update(u), update(p);
    u = p;
}

int get_balance(int u) {
    return h[l[u]] - h[r[u]];
}

void insert(int& u, int w) {
    // null
    if (!u) u = ++ idx, v[u] = w;
    else if (w < v[u]) {
        insert(l[u], w);
        if (get_balance(u) == 2) {
            if (get_balance(l[u]) == 1) R(u);
            else L(l[u]), R(u);
        }
    } else {
        insert(r[u], w);
        if (get_balance(u) == -2) {
            if (get_balance(r[u]) == -1) L(u);
            else R(r[u]), L(u);
        }
    }
    update(u);
}

vector<int> level;
bool BFS(int u) {
    queue<int> q;
    q.push(u);
    bool flag = false;
    bool res = true;
    while (q.size()) {
        int root = q.front(); q.pop();
        // cout << v[root] << endl;
        level.push_back(v[root]);
        if (l[root] != 0) {
            if (flag) res = false;
            q.push(l[root]);
        } else flag = true;

        if (r[root] != 0) {
            if (flag) res = false;
            q.push(r[root]);
        } else flag = true;
    }
    return res;
}

inline void solution() {
    int n, root = 0;
    cin >> n;
    while (n -- ) {
        int w;
        cin >> w;
        insert(root, w);
    }

    bool checked = BFS(root);
    cout << level[0];
    for (int i = 1; i < level.size(); i ++ ) cout << " " << level[i];
    cout << endl;
    if (checked) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}